package com.threeti.mecool.shared.util;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import javax.persistence.MappedSuperclass;

import com.threeti.mecool.framework.util.Lists;


public abstract class AbstractTreeNode<T> implements Serializable,TreeNode<T> {

  private T id;

  private String name;

  private T parentId;

  private AbstractTreeNode<T> parent;

  private List<AbstractTreeNode<T>> childs = Lists.newArrayList();

  public AbstractTreeNode(T id) {
    super();
    this.id = id;
  }

  public AbstractTreeNode(T id, String name) {
    super();
    this.id = id;
    this.name = name;
  }

  public T getId() {
    return id;
  }

  public String getName() {
    return name;
  }

  public AbstractTreeNode<T> getParent() {
    return parent;
  }

  public void setParent(AbstractTreeNode<T> parent) {
    this.parent = parent;
  }

  public List<AbstractTreeNode<T>> getChilds() {
    return Collections.unmodifiableList(childs);
  }

  public T getParentId() {
    return parentId;
  }


  public AbstractTreeNode<T> addChild(AbstractTreeNode<T> node) {
    node.setParent(this);
    node.setParentId(this.getId());
    childs.add(node);
    return this;
  }

  protected AbstractTreeNode() {
  }

  protected void setName(String name) {//jay:should only open for getter/setter reflection injection
    this.name = name;
  }
  protected void setParentId(T parentId) {
    this.parentId = parentId;
  }
  
}
